package com.demo.webapp.views.freemarker.directive.core;

import java.io.IOException;
import java.io.Writer;
import java.util.Map;

import freemarker.core.Environment;
import freemarker.core.Environment.TemplateDirectiveBodyEx;
import freemarker.template.SimpleHash;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;
import freemarker.template.TemplateModelException;

/**
 * 自定义指令: 分页
 * 该分页自定义指令需要满足对象
 * @author ryuu.kk
 *
 */
public class PageDirective extends PageContextDirectiveSupport {

	/**
	 * 页面模板名
	 */
	private static final String PAGE_NAME = "classpath:/com/demo/webapp/views/freemarker/directive/template/page.ftl";
	
	@SuppressWarnings("rawtypes")
	@Override
	public void preWriter(Environment env, TemplateDirectiveBodyEx bodyEx,
			TemplateModel[] loopVars, SimpleHash hash, Map params)
			throws IOException, TemplateException {
		
	}
	
	@SuppressWarnings("rawtypes")
	@Override
	public String getTemplatePath(Map params) {
		String path = "";
		try {
			path = getString("path", params, PAGE_NAME);
		} catch (TemplateModelException e) {}
		return path;
	}
	
	@Override
	public void afterInvoke(Writer writer) {
		// nothing.
	}
}
